/**
 * FileName: MqttAuthController
 * Author: Wb
 * Date: 2025/9/26 9:19
 * Description:
 * History:
 */
package org.test.device.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.test.device.params.MqttAuthParam;
import org.test.device.service.MqttAuthService;
import org.test.device.utils.ResultData;

import java.util.HashMap;
import java.util.Map;

/**
 * 〈一句话功能简述〉<br>
 * 〈产品对接设备的验证方式〉
 *
 * @author Wb
 * @create 2025/9/26
 * @since 1.0.0
 */
@Slf4j
@Tag(name = "MQTT认证接口", description = "产品对接设备的验证方式")
@RestController
@RequestMapping("mqtt")
public class MqttAuthController {

    @Autowired
    MqttAuthService mqttAuthService;

    /**
     * @Author Wb
     * @Description 产品对接设备验证接口
     * @Date 15:32 2025/9/26
     * @Param [param]
     * @Return org.test.device.utils.ResultData
     */
    @PostMapping("auth")
    public ResultData mqttAuth(@RequestBody MqttAuthParam param){
        // 调用认证服务进行验证
        return mqttAuthService.authenticate(
                param.getClientId(),
                param.getUsername(),
                param.getPassword()
        );

//        if (isAuthenticated) {
//            // 认证通过，返回允许连接
//            resultMap.put("result", "yes");
//            // 可以在此设置客户端的最大QoS、保留消息等权限
//            resultMap.put("max_qos", 1);
//            resultMap.put("allow_anonymous", false);
//            return new ResultData("设备认证成功！",resultMap);
//        } else {
//            // 认证失败
//            resultMap.put("result", "no");
//            return new ResultData("设备认证失败！");
//        }
    }
}